using Microsoft.VisualBasic;
using Ocelot.DependencyInjection;
using Ocelot.Middleware;
using Ocelot.Provider.Consul;
using ServiceManagement.Gateway;

var builder = WebApplication.CreateBuilder(args);

//注册自定义的配置文件
builder.Configuration.AddJsonFile("configuration.json", false, true);

//注册Ocelot和Consul配置
builder.Services.AddOcelot().AddConsul<MyConsulServiceBuilder>();

//注册跨域
builder.Services.AddCors(c =>
{
    c.AddPolicy("all", b =>
    {
        b.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader();
    });
});

var app = builder.Build();

// 添加测试端点
app.MapGet("/test", () => "Gateway is working!");

//使用跨域
app.UseCors("all");

//使用Ocelot中间件（异步请求处理）
await app.UseOcelot();

app.Run();
